<template>
	<view class="container pbsafe_56">
		<view class="mt_8 richBox">
			<rich-text :nodes="htmlText"></rich-text>
		</view>
		<view class="plr_12 ptb_16 bc_fff">
			<view class="fz_16 fb">
				好物推荐
			</view>
			<view class="flow_x fx mt_8">
				<view class="list_item" v-for="item, index in goodsList" :key="index">
					<GoodsCard type="simple_card" :data="item" :toDetail="false" />
				</view>
			</view>
		</view>
		<view class="pf b_0 l_0 r_0 pt_8 pbsafe_8 plr_16 bc_fff">
			<button class="w100 custom_btn primary lh_40 fz_14 br_57" @click="handleUrl">提交资料成为经销商</button>
		</view>
	</view>
</template>

<script>
import GoodsCard from '@/components/goods/GoodsCard.vue'
import api from "@/service/config/api";
export default {
	components: {
		GoodsCard
	},
	data() {
		return {
			html: '',
			goodsList: [],
			htmlText: ""
		}
	},
	onLoad() {
		this.getIntroduce()
		this.getGoodsList()
	},
	onShow() {
	},
	onBackPress() {
		uni.navigateBack({
			delta: 1,
			success() {
				console.log("页面返回")
				const pages = getCurrentPages()
				const prevPage = pages[pages.length - 2]
				prevPage.reloadPage()
			}
		})
	},
	methods: {
		// 获取平台介绍
		getIntroduce() {
			api.get("/base/api/tAppletProtocol/type", {
				key: "about_us"
			}).then(res => {
				if (res && res.code == 0) {
					this.htmlText = res.data.valueStr.replace(/style=\"\"/gi, '').replace(/\<img/gi, '<img style="max-width:100%";height:auto');
				}
			})
		},
		getInfo() {
			return new Promise(resolve => {
				api.get('/base/api/tAppletProtocol/type', {
					key: 'about_us',
				}, {
					noHideLoading: true
				}).then(res => {
					this.html = res.data.valueStr.replace(/style=\"\"/gi, '').replace(/\<img/gi, '<img style="max-width:100%";height:auto');
				}).finally(() => {
					resolve()
				})
			})
		},
		// 获取好物推荐列表
		getGoodsList() {
			return new Promise(resolve => {
				api.get('/goods/api/product/goodProductList', {
					size: 10,
					current: 1,
					userType: this.$store.state.userInfo.identityType || 1,					...this.$store.state.userInfo.customerId ? {						customerId: this.$store.state.userInfo.customerId
					} : {},
					orderBy: 0,
					appletType: this.$store.state.appType === this.$base.ADMIN_TYPE ? 0 : 1,
				}, {
					noHideLoading: true
				}).then(res => {
					this.goodsList = res.data && res.data.records ? res.data
						.records : []
				}).finally(() => {
					resolve()
				})
			})
		},
		handleUrl() {
			uni.navigateTo({
				url: '/pages/account/pages/verify'
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.richBox {
	padding: 32rpx;
}

.list_item+.list_item {
	margin-left: 16rpx;
}
</style>